
$(function()
{
	var demo=1;
	$.ajax({
		url:"../../shareTask.action",
		data:{"taskId":getUrlParam("url")},
		dataType:"json",
		type:"post",
		success:function(data)
		{
			for(var i=0;i<data.length;i++)
			{
				$("#body").append('<div class="row">'
						+'<div class="col-md-1">'
						+'<label>'+data[i].receiverid+'</label>'
						+'</div>'
						+'<div class="col-md-8">'
						+'<div class="progress">'
						+'<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width:10%;">'
						+''+data[i].votesnumber+'票'
						+'</div>'
						+'</div>'
						+'</div>'
						+'<div class="col-md-2 col-md-offset-1">'
						+'<input class="btn btn-default btn-success" type="button" id="id'+i+'" onclick="vote(id)" value="投票"/>'
						+'</div>'
						+'</div>');
			}
		}
	});
	
});
function vote(id)
{
	var temId="#"+id;
	console.log(temId);
	var value=$(temId).parent().prev().children().children().text();
	console.log(value);
	var number=value.substring(0,value.length-1);
	console.log(number);
	$(temId).parent().prev().children().children().remove();
	appendShow(temId,number);
	$(temId).attr("disabled",true);
	$(temId).val("已投票");
}
function appendShow(id,number)
{
	var i=parseInt(number)+1;
	$(id).parent().prev().children().
	append('<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="2" aria-valuemin="0" aria-valuemax="100" style="min-width: 2em; width:'+i+'%;">'
	+''+i+'票'
	+'</div>');
}
function getUrlParam(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
    var r = window.location.search.substr(1).match(reg);  //匹配目标参数
    if (r != null) return unescape(r[2]); return null; //返回参数值
}
